
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 01/22/2014 21:47:20
-- Generated from EDMX file: C:\Documents and Settings\aluno\my documents\visual studio 2010\Projects\cursocsharptec\exercicio-entity\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ExercicioEntity];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_TurmaAluno]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AlunoSet] DROP CONSTRAINT [FK_TurmaAluno];
GO
IF OBJECT_ID(N'[dbo].[FK_TurmaProfessor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProfessorSet] DROP CONSTRAINT [FK_TurmaProfessor];
GO
IF OBJECT_ID(N'[dbo].[FK_AlunoEndereco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EnderecoSet] DROP CONSTRAINT [FK_AlunoEndereco];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AlunoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AlunoSet];
GO
IF OBJECT_ID(N'[dbo].[ProfessorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProfessorSet];
GO
IF OBJECT_ID(N'[dbo].[EnderecoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EnderecoSet];
GO
IF OBJECT_ID(N'[dbo].[TurmaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TurmaSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AlunoSet'
CREATE TABLE [dbo].[AlunoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [Turma_Id] int  NOT NULL
);
GO

-- Creating table 'ProfessorSet'
CREATE TABLE [dbo].[ProfessorSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nome] nvarchar(max)  NOT NULL,
    [Turma_Id] int  NOT NULL
);
GO

-- Creating table 'EnderecoSet'
CREATE TABLE [dbo].[EnderecoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Rua] nvarchar(max)  NOT NULL,
    [Aluno_Id] int  NOT NULL
);
GO

-- Creating table 'TurmaSet'
CREATE TABLE [dbo].[TurmaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Codigo] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'AlunoSet'
ALTER TABLE [dbo].[AlunoSet]
ADD CONSTRAINT [PK_AlunoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProfessorSet'
ALTER TABLE [dbo].[ProfessorSet]
ADD CONSTRAINT [PK_ProfessorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EnderecoSet'
ALTER TABLE [dbo].[EnderecoSet]
ADD CONSTRAINT [PK_EnderecoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TurmaSet'
ALTER TABLE [dbo].[TurmaSet]
ADD CONSTRAINT [PK_TurmaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Turma_Id] in table 'AlunoSet'
ALTER TABLE [dbo].[AlunoSet]
ADD CONSTRAINT [FK_TurmaAluno]
    FOREIGN KEY ([Turma_Id])
    REFERENCES [dbo].[TurmaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TurmaAluno'
CREATE INDEX [IX_FK_TurmaAluno]
ON [dbo].[AlunoSet]
    ([Turma_Id]);
GO

-- Creating foreign key on [Turma_Id] in table 'ProfessorSet'
ALTER TABLE [dbo].[ProfessorSet]
ADD CONSTRAINT [FK_TurmaProfessor]
    FOREIGN KEY ([Turma_Id])
    REFERENCES [dbo].[TurmaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TurmaProfessor'
CREATE INDEX [IX_FK_TurmaProfessor]
ON [dbo].[ProfessorSet]
    ([Turma_Id]);
GO

-- Creating foreign key on [Aluno_Id] in table 'EnderecoSet'
ALTER TABLE [dbo].[EnderecoSet]
ADD CONSTRAINT [FK_AlunoEndereco]
    FOREIGN KEY ([Aluno_Id])
    REFERENCES [dbo].[AlunoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AlunoEndereco'
CREATE INDEX [IX_FK_AlunoEndereco]
ON [dbo].[EnderecoSet]
    ([Aluno_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------